﻿using GammaJul.ReSharper.GammaXaml.ContextActions.Xaml;
using GammaJul.ReSharper.GammaXaml.Highlightings.Xaml;
using JetBrains.ReSharper.Daemon.Stages;
using JetBrains.ReSharper.Psi.Tree;
using JetBrains.ReSharper.Psi.Xaml.Tree;

namespace GammaJul.ReSharper.GammaXaml.Analysis.Xaml {

	/// <summary>
	/// Analyzer that checks that :
	///  - A RelativeSource can be converted to x:Static
	/// </summary>
	public class RelativeSourceAnalysis : XamlAnalysis {
		
		public override bool InteriorShouldBeProcessed(ITreeNode element) {
			return !(element is IRelativeSourceUsage) && base.InteriorShouldBeProcessed(element);
		}

		public override void ProcessBeforeInterior(ITreeNode element, IHighlightingConsumer highlightings) {
			var relativeSource = element as IRelativeSourceUsage;
			if (relativeSource != null && RelativeSourceToXStaticActionBase.IsAvailable(relativeSource))
				highlightings.AddHighlighting(new XStaticCanBeUsedHighlighting(relativeSource), XamlFile);
		}

	}

}